% n = dimension, p = order

%x = load('../Data/d1.txt');
%p = 3;
tol = 1e-4;
cvx_solver sdpt3;
load('../Data/cycle_graph.mat');
% TODO resolve name conflicts
%p = k;
%x = X';
%clear X;

[N,n] = size(x);
C = windowed_est(x, p);

A = [S A];
sensitivity = [];
specificity = [];
for gamma=0:0.05:2.5
	X = reg_ml(C, n, p, gamma);
	B0 = sqrtm(X(1:n,1:n));
	B1p = inv(B0)*X(1:n,(1+n):(n*(p+1)));
	B = [B0 B1p];
	A_est = [inv(B0)^2 inv(B0)*B1p];
% TODO check sparsity in A or Y?
	tp = sum(sum((abs(A) <  tol) & (abs(A_est) <  tol)));
	fp = sum(sum((abs(A) >= tol) & (abs(A_est) <  tol)));
	tn = sum(sum((abs(A) >= tol) & (abs(A_est) >= tol)));
	fn = sum(sum((abs(A) <  tol) & (abs(A_est) >= tol)));
	sensitivity = [sensitivity tp/(tp+fn)];
	specificity = [specificity tn/(tn+fp)];
end
